package com.example.myapplication;

import android.annotation.SuppressLint;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

@SuppressLint("ValidFragment")
public class MyFragment extends Fragment {
    Context context;
    Bundle Arguments1;

    TextView text;
    Button f2f;
    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment1,container,false);
        context = getActivity();
        text=view.findViewById(R.id.text1);
        f2f=view.findViewById(R.id.sent);
        text.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Bundle bundle = getArguments();
                String result = bundle.getString("MainActivity");
                ((TextView)v).setText(result);
            }
        });
        f2f.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                getArguments().putString("MyFragment", "Hello,Activity");
            }
        });
        return view;
        //使用handler和方法传参是主要使用的方式
    }
}
